import React from 'react';
import {
  ActivityIndicator,
  AsyncStorage,
  StatusBar,
  StyleSheet,
  View,
} from 'react-native';

import { connect } from 'react-redux'

import { getAuthority,setAuthority } from '../utils/authority';

class AuthLoadingScreen extends React.Component {

  componentDidMount(){
    this._bootstrapAsync();
  }
  // Fetch the token from storage then navigate to our appropriate place
  _bootstrapAsync = async () => {
    let authority = await getAuthority();
    console.log(authority);
    if(authority){
        this.props.dispatch({ type: 'user/setUserInfo' ,payload:authority});
        this.props.navigation.navigate('App');
    }
    else{
        this.props.navigation.navigate('Auth');
    }
  };

  // Render any loading content that you like here
  render() {
    
    return (
      <View style={{flex: 1,justifyContent: 'center',}}>
          <ActivityIndicator size="large" color="#0000ff" />
      </View>
    );
  }
}

//export default AuthLoadingScreen;
export default connect(({ user }) => ({user,}))(AuthLoadingScreen);